//
//  LGChatNavigationView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/22.
//

#import "LGChatPatientNavigation.h"

@interface LGChatPatientNavigation()

/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UIView *statusView;
/**   */
@property (nonatomic , strong)UIButton *typeBtn;
/**   */
@property (nonatomic , strong)UIImageView *statusTip;

@end

@implementation LGChatPatientNavigation

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setShowStatusView:(BOOL)showStatusView{
    _showStatusView = showStatusView;
    self.statusView.hidden = !showStatusView;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSDictionary *patientDic = dataDic[@"patient"];
    self.nameLabel.text = LGNSString(patientDic[@"realname"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",patientDic[@"gender"],patientDic[@"age"]];
    
    NSString *type = LGNSString(dataDic[@"appointment_type"]);
    if([type isEqualToString:@"2"]){
        //视频咨询
        [self.typeBtn setTitle:@"视频咨询" forState:UIControlStateNormal];
        [self.typeBtn setImage:[UIImage imageNamed:@"聊天咨询-视频门诊"] forState:UIControlStateNormal];
        
        
    }else if([type isEqualToString:@"3"]){
        //专家(图文咨询)
        [self.typeBtn setTitle:@"专家咨询" forState:UIControlStateNormal];
        [self.typeBtn setImage:[UIImage imageNamed:@"聊天咨询-专家咨询"] forState:UIControlStateNormal];
        
        
    }else if([type isEqualToString:@"4"]){
        //团队咨询
        [self.typeBtn setTitle:@"团队咨询" forState:UIControlStateNormal];
        [self.typeBtn setImage:[UIImage imageNamed:@"聊天咨询-团队咨询"] forState:UIControlStateNormal];
    }
    
    NSString *state = LGNSString(dataDic[@"state"]);
    //10：待支付 20：已取消 30：待接诊 31：咨询中   40 已完成  41：已爽约  42 ：未接通  50：已退款
    if([state isEqualToString:@"30"]){
        //未就诊
        self.timeLabel.hidden = YES;
        self.unitLabel.hidden = YES;
        self.statusTip.hidden = NO;
        self.statusBtn.selected = YES;
        self.statusBtn.userInteractionEnabled = NO;//NO
        self.statusBtn.frame = CGRectMake(Screen_W-viewPix(12)-80, viewPix(9), 80, viewPix(26));
        
    }else if ([state isEqualToString:@"31"]){
        //咨询中
        self.timeLabel.hidden = NO;
        self.unitLabel.hidden = NO;
        self.unitLabel.text = @"后结束";
        self.statusTip.hidden = NO;
        self.statusBtn.selected = YES;
        self.statusBtn.userInteractionEnabled = YES;
        self.statusBtn.frame = CGRectMake(Screen_W-viewPix(12)-80, viewPix(9), 80, viewPix(26));
        
    }else{
        //其他
        self.timeLabel.hidden = YES;
        self.unitLabel.hidden = YES;
        self.statusTip.hidden = NO;
        self.statusBtn.selected = NO;
        self.statusBtn.userInteractionEnabled = YES;
        CGFloat statusW = [state isEqualToString:@"50"]?90:80;
        self.statusBtn.frame = CGRectMake(Screen_W-viewPix(12)-statusW, viewPix(9), statusW, viewPix(26));
    }
    [self.statusBtn setTitle:LGNSString(dataDic[@"state_name"]) forState:UIControlStateNormal];
}




#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.backBtn];
    [self addSubview:self.nameLabel];
    [self addSubview:self.ageLabel];
    [self addSubview:self.tipView];
    [self addSubview:self.patientBtn];
    [self addSubview:self.teamBtn];
    [self addSubview:self.statusView];
    [self.statusView addSubview:self.typeBtn];
    [self.statusView addSubview:self.timeLabel];
    [self.statusView addSubview:self.unitLabel];
    [self.statusView addSubview:self.statusBtn];
    [self.statusBtn addSubview:self.statusTip];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(statusBarHeight+5);
        make.centerX.equalTo(self);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(1);
        make.centerX.equalTo(self);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
        make.centerY.equalTo(self.nameLabel.mas_bottom);
        make.width.height.equalTo(@(12));
    }];
    [self.patientBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel).offset(-viewPix(16));
        make.right.equalTo(self.nameLabel).offset(viewPix(20));
        make.top.equalTo(self.nameLabel);
        make.bottom.equalTo(self.ageLabel);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.statusView.mas_centerX).offset(5);
        make.centerY.equalTo(self.statusView);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_right).offset(5);
        make.centerY.equalTo(self.statusView);
    }];
    [self.statusTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.statusBtn).offset(-viewPix(6));
        make.centerY.equalTo(self.statusBtn);
        make.width.height.equalTo(@(viewPix(12)));
    }];
}
-(UIButton *)backBtn{
    if(!_backBtn){
        _backBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(5, statusBarHeight, 44, 44);
        [_backBtn setImage:kNavBackImage forState:UIControlStateNormal];
        [_backBtn setImage:kNavBackImage forState:UIControlStateHighlighted];
    }
    return _backBtn;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@" " colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@" " colorString:@"#999999" textFont:LGFont(13) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"聊天咨询-查看患者"]];
    }
    return _tipView;
}

-(UIButton *)teamBtn{
    if(!_teamBtn){
        _teamBtn = [UIButton buttonWithImage:@"聊天咨询-团队成员" selectImage:@"聊天咨询-团队成员"];
        [_teamBtn setImage:[UIImage imageNamed:@"聊天咨询-团队成员"] forState:UIControlStateHighlighted];
        _teamBtn.frame = CGRectMake(Screen_W-49, statusBarHeight, 44, 44);
        _teamBtn.hidden = YES;
    }
    return _teamBtn;
}

-(UIButton *)patientBtn{
    if(!_patientBtn){
        _patientBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _patientBtn;
}

-(UIView *)statusView{
    if(!_statusView){
        _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, topBarHeight, Screen_W, viewPix(44))];
        _statusView.backgroundColor = [UIColor colorWithString:@"#FCFAFF"];
    }
    return _statusView;
}

-(UIButton *)typeBtn{
    if(!_typeBtn){
        _typeBtn = [UIButton buttonWithTitle:@" " titleFont:LGFont(16) textColor:@"#333333" imageName:@""];
        _typeBtn.frame = CGRectMake(viewPix(12), 0, viewPix(100), viewPix(44));
        _typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
    }
    return _typeBtn;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@" " colorString:@"#1F6CC6" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _timeLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"后结束" colorString:@"#000000" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _unitLabel;
}

-(UIButton *)statusBtn{
    if(!_statusBtn){
        _statusBtn = [UIButton buttonWithTitle:@"已停诊" titleFont:LGFont(13) normalColor:@"#333333" selectColor:@"#333333" normalImage:@"门诊咨询-已停诊" selectImage:@"门诊咨询-接诊中"];
        _statusBtn.frame = CGRectMake(Screen_W-viewPix(92), viewPix(9), viewPix(80), viewPix(26));
        _statusBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _statusBtn.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(7), 0, 0);
        _statusBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(10), 0, 0);
        _statusBtn.cornerRidus = viewPix(13);
        _statusBtn.userInteractionEnabled = YES;
        [_statusBtn setBackgroundColor:[UIColor colorWithString:@"#E8E9EB"] forState:UIControlStateNormal];
        [_statusBtn setBackgroundColor:[UIColor colorWithString:@"#DFEEFF"] forState:UIControlStateSelected];
    }
    return _statusBtn;
}

-(UIImageView *)statusTip{
    if(!_statusTip){
        _statusTip = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTipDown12"]];
        _statusTip.hidden = YES;
    }
    return _statusTip;
}

@end
